$(function() {
	var $write = $('#write'), $write1 = $('#write1'), $write2 = $('#write2'), shift = false, capslock = false;
	// Download by http://www.codefans.net
	$('#keyboard li')
			.click(
					function() {
						var $this = $(this), character = $this.html(); // If
						// it's
						// a
						// lowercase
						// letter, nothing
						// happens to this
						// variable

						if (character == '.') {
							if ($write.html() == '') {
								return false;
							} else if ($write.html().indexOf('.') > 0) {
								return false;
							}
						}

						if ($write.html().indexOf('.') > 0
								&& $this.hasClass('symbol')
								&& ($write.html().length - $write.html()
										.indexOf('.')) == 3) {
							return false;
						}

						// Shift keys
						if ($this.hasClass('left-shift')
								|| $this.hasClass('right-shift')) {
							$('.letter').toggleClass('uppercase');
							$('.symbol span').toggle();

							shift = (shift === true) ? false : true;
							capslock = false;
							return false;
						}
						// Caps lock
						if ($this.hasClass('capslock')) {
							$('.letter').toggleClass('uppercase');
							capslock = true;
							return false;
						}

						// Delete
						if ($this.hasClass('delete')) {
							var html = $write.html();

							$write.html(html.substr(0, html.length - 1));
							$write2.html(decimal(accSub($write.html(), $write1
									.html()), 2));
							return false;
						}

						// Special characters
						if ($this.hasClass('symbol'))
							character = $('span:visible', $this).html();

						// Uppercase letter
						if ($this.hasClass('uppercase'))
							character = character.toUpperCase();

						// Remove shift once a key is clicked.
						if (shift === true) {
							$('.symbol span').toggle();
							if (capslock === false)
								$('.letter').toggleClass('uppercase');

							shift = false;
						}

						// Add the character
						$write.html($write.html() + character);
						// 设置零钱
						$write2.html(decimal(accSub($write.html(), $write1
								.html()), 2));

					});
});